package com.love.marriage.dailyRecommendationUserInfo.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.dailyRecommendationUserInfo.entity.DailyRecommendationUserInfo;
import com.love.marriage.dailyRecommendationUserInfo.mapper.DailyRecommendationUserInfoMapper;
import com.love.marriage.dailyRecommendationUserInfo.service.DailyRecommendationUserInfoService;
import com.love.marriage.dailyRecommendationUserInfo.vo.DailyRecommendationUserInfoVo;
import com.love.marriage.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * description:  每日推荐用户表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-15 23:03:02
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class DailyRecommendationUserInfoServiceImp extends ServiceImpl<DailyRecommendationUserInfoMapper, DailyRecommendationUserInfo> implements DailyRecommendationUserInfoService {

    private final DailyRecommendationUserInfoMapper dailyRecommendationUserInfoMapper;

    @Override
    public Page<DailyRecommendationUserInfoVo> getPage(Long pageNum, Long pageSize, DailyRecommendationUserInfoVo dailyRecommendationUserInfoVo) {
        Page<DailyRecommendationUserInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return dailyRecommendationUserInfoMapper.getPage(page, dailyRecommendationUserInfoVo);
    }

    @Override
    public DailyRecommendationUserInfoVo queryDailyRecommendationUserInfo(Long id) {
        return dailyRecommendationUserInfoMapper.queryDailyRecommendationUserInfo(id);
    }

    @Override
    public DailyRecommendationUserInfoVo addDailyRecommendationUserInfo(DailyRecommendationUserInfoVo dailyRecommendationUserInfoVo) {
        DailyRecommendationUserInfo dailyRecommendationUserInfo = new DailyRecommendationUserInfo();
        BeanUtils.copyProperties(dailyRecommendationUserInfoVo, dailyRecommendationUserInfo);
        dailyRecommendationUserInfoMapper.insert(dailyRecommendationUserInfo);
        DailyRecommendationUserInfoVo res = new DailyRecommendationUserInfoVo();
        BeanUtils.copyProperties(dailyRecommendationUserInfo, res);
        return res;
    }

    @Override
    public DailyRecommendationUserInfoVo updateDailyRecommendationUserInfo(DailyRecommendationUserInfoVo dailyRecommendationUserInfoVo) {
        DailyRecommendationUserInfo dailyRecommendationUserInfo = new DailyRecommendationUserInfo();
        BeanUtils.copyProperties(dailyRecommendationUserInfoVo, dailyRecommendationUserInfo);
        dailyRecommendationUserInfoMapper.updateById(dailyRecommendationUserInfo);
        return dailyRecommendationUserInfoVo;
    }

    @Override
    public Boolean deleteDailyRecommendationUserInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        dailyRecommendationUserInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
